package com.quxuecx.springcloud.entities;

import java.io.Serializable;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author: shaofeer
 * <p>
 * @qq: 337081267
 * <p>
 * @CSDN: http://blog.csdn.net/pyfysf
 * <p>
 * @blog: http://wintp.top
 * <p>
 * @email: shaofeer@163.com
 * <p>
 * @time: 2020/6/22
 */
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CommentResult<T> implements Serializable {
    private Integer code;
    private String message;
    private String requestId = IdUtil.fastUUID();
    private Long timestamp = System.currentTimeMillis();

    private T data;

    public CommentResult(Integer code, String message) {
        this.code = code;
        this.message = message;
        this.data = null;
    }

    public CommentResult error() {
        this.message = "请求失败";
        this.code = 500;

        return this;
    }

    public CommentResult<T> success(T data) {
        this.message = "请求成功";
        this.code = 200;
        this.data = data;
        return this;
    }

}
